public class LinearSearch {
    // 构造函数
    private LinearSearch(){}

    // 使用泛型
    public static <E> int search(E[] data, E target){
        for(int i = 0; i < data.length; i++)
            if(data[i].equals(target))
                return i;
        return -1;
    }

//    public static void main(String[] args){
//        int[] dataSize = {1000000,10000000};
//        for(int n:dataSize) {
//            Integer[] data = ArrayGenerator.generateOrderedArray(n);
//            long startTime = System.nanoTime();
//            for (int k = 0; k < 100; k++)
//                LinearSearch.search(data, n);
//            long endTime = System.nanoTime();
//            double time = (endTime - startTime) / 1000000000.0;
//            System.out.println("n = " + n + ", 100 runs :" + time + " s");
//        }
//
//        Character[] data2 = {'a','b','c','d'};
//        int res2 = LinearSearch.search(data2,'c');
//        System.out.println(res2);
//
//
//        Student[] students = {new Student("Alice"),
//                              new Student("Bobo"),
//                              new Student("Charles")};
//        Student bobo = new Student("Bobo");
//        int res3 = LinearSearch.search(students,bobo);
//        System.out.println(res3);
//    }
}
